package com.origin.bluetooth.adapter

import android.bluetooth.BluetoothDevice
import android.bluetooth.le.ScanResult
import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import com.origin.baselibrary.activity.BaseActivity
import com.origin.bluetooth.R
import com.origin.bluetooth.databinding.ItemBluetoothBinding
import com.origin.uilibrary.xrecycleview.adapter.BaseRecycleAdapter
import com.origin.uilibrary.xrecycleview.viewholder.BaseViewHolder

class BlueToothAdapter(list: MutableList<BluetoothDevice>, context: Context) : BaseRecycleAdapter<BluetoothDevice>(list, context) {
    override fun setItemData(holder: BaseViewHolder, item: BluetoothDevice, position: Int) {
        if (holder.binding is ItemBluetoothBinding) {
            val itemBluetoothBinding = holder.binding as ItemBluetoothBinding

            itemBluetoothBinding.title.text = "${item.name ?: item.address}===${item.type}"  ;
            itemBluetoothBinding.title.setOnClickListener {
                mItemClickListener?.onItemClick(position,item,it)
            }
        }
    }

    override fun getViewResource(inflater: LayoutInflater, viewType: Int, parent: ViewGroup): BaseViewHolder {
        val itemBluetoothBinding = loadDataBinding<ItemBluetoothBinding>(inflater, parent, R.layout.item_bluetooth)
        return BaseViewHolder(itemBluetoothBinding)
    }
}